package com.sz.biz.logistics.serialno.utils;

import com.alibaba.druid.util.StringUtils;

import java.util.Arrays;
import java.util.List;

/**
 * Function: 手机号验证 <br>
 * Author: Johnboy <br>
 * Date: 2017-12-09 20:35:00
 */
public class TelPhoneValid {
    private static List<TelPrefixData> list = Arrays.asList(new TelPrefixData(130 , 139) , new TelPrefixData(150 , 199));
    private static final int TEL_LENGTH = 11;

    public static boolean isPhoneNumber(String tel) {
        if (tel == null) {
            return false;
        }
        if (tel.length() != TEL_LENGTH) {
            return false;
        }
        if (! StringUtils.isNumber(tel)) {
            return false;
        }
        int startNumber = Integer.valueOf(tel.substring(0 , 3));
        int result = (int) list.stream().filter(e -> e.getMin() <= startNumber && e.getMax() >= startNumber).count();
        if (result > 0) {
            return true;
        }else {
            return false;
        }
    }
}
